﻿// This class is "generated" and will be overwritten.
// Your customizations should be made in UsuarioRecord.cs

using System;
using System.Collections;
using System.Data.SqlTypes;
using BaseClasses;
using BaseClasses.Data;
using BaseClasses.Data.SqlProvider;

namespace EnGasAdoAPP.Business
{

/// <summary>
/// The generated superclass for the <see cref="UsuarioRecord"></see> class.
/// </summary>
/// <remarks>
/// This class is not intended to be instantiated directly.  To obtain an instance of this class, 
/// use the methods of the <see cref="UsuarioTable"></see> class.
/// </remarks>
/// <seealso cref="UsuarioTable"></seealso>
/// <seealso cref="UsuarioRecord"></seealso>
public class BaseUsuarioRecord : PrimaryKeyRecord, IUserIdentityRecord
{

	public readonly static UsuarioTable TableUtils = UsuarioTable.Instance;

	// Constructors
 
	protected BaseUsuarioRecord() : base(TableUtils)
	{
		this.InsertingRecord += 
			new BaseClasses.IRecordWithTriggerEvents.InsertingRecordEventHandler(this.UsuarioRecord_InsertingRecord); 
		this.UpdatingRecord += 
			new BaseClasses.IRecordWithTriggerEvents.UpdatingRecordEventHandler(this.UsuarioRecord_UpdatingRecord); 
		this.ReadRecord +=
            new BaseClasses.IRecordWithTriggerEvents.ReadRecordEventHandler(this.UsuarioRecord_ReadRecord); 
	}

	protected BaseUsuarioRecord(PrimaryKeyRecord record) : base(record, TableUtils)
	{
	}
	
	
	//Audit Trail methods
	
	//Evaluates Initialize when->Reading record formulas specified at the data access layer
    protected virtual void UsuarioRecord_ReadRecord(Object sender,System.EventArgs e)
    {
        //Apply Initialize->Reading record formula only if validation is successful.
                UsuarioRecord UsuarioRec = (UsuarioRecord)sender;
        if(UsuarioRec != null && !UsuarioRec.IsReadOnly ){
                }
    
    }
        
	//Evaluates Initialize when->Inserting formulas specified at the data access layer
    protected virtual void UsuarioRecord_InsertingRecord(Object sender,System.ComponentModel.CancelEventArgs e)
    {
        //Apply Initialize->Inserting formula only if validation is successful.
                UsuarioRecord UsuarioRec = (UsuarioRecord)sender;
        Validate_Inserting();
        if(UsuarioRec != null && !UsuarioRec.IsReadOnly ){
                }
    
    }
    
    //Evaluates Initialize when->Updating formulas specified at the data access layer
    protected virtual void UsuarioRecord_UpdatingRecord(Object sender,System.ComponentModel.CancelEventArgs e)
    {
        //Apply Initialize->Updating formula only if validation is successful.
                UsuarioRecord UsuarioRec = (UsuarioRecord)sender;
        Validate_Updating();
        if(UsuarioRec != null && !UsuarioRec.IsReadOnly ){
                }
    
    }

   //Evaluates Validate when->Inserting formulas specified at the data access layer
	protected virtual void Validate_Inserting()
	{
		string fullValidationMessage = "";
		string validationMessage = "";
		
		

		if(validationMessage != "" && validationMessage.ToLower() != "true")
            fullValidationMessage = fullValidationMessage + validationMessage + "\r\n"; 
		
        if(fullValidationMessage != "")
			throw new Exception(fullValidationMessage);
	}
 
	//Evaluates Validate when->Updating formulas specified at the data access layer
	protected virtual void Validate_Updating()
	{
		string fullValidationMessage = "";
		string validationMessage = "";
		
		

		if(validationMessage != "" && validationMessage.ToLower() != "true")
            fullValidationMessage = fullValidationMessage + validationMessage + "\r\n"; 
		
        if(fullValidationMessage != "")
			throw new Exception(fullValidationMessage);
	}
	public virtual string EvaluateFormula(string formula, BaseRecord  dataSourceForEvaluate, string format)
    {
        Data.BaseFormulaEvaluator e = new Data.BaseFormulaEvaluator();
        
        // All variables referred to in the formula are expected to be
        // properties of the DataSource.  For example, referring to
        // UnitPrice as a variable will refer to DataSource.UnitPrice
        e.DataSource = dataSourceForEvaluate;

        Object resultObj = e.Evaluate(formula);
        if(resultObj == null) 
			return "";
        return resultObj.ToString();
	}

#region "IUserRecord Members"

	//Get the user's unique identifier
	public string GetUserId()
	{
		return this.GetString(((BaseClasses.IUserTable)this.TableAccess).UserIdColumn);
	}

#endregion


#region "IUserIdentityRecord Members"

	//Get the user's name
	public string GetUserName()
	{
		return this.GetString(((BaseClasses.IUserIdentityTable)this.TableAccess).UserNameColumn);
	}

	//Get the user's password
	public string GetUserPassword()
	{
		return this.GetString(((BaseClasses.IUserIdentityTable)this.TableAccess).UserPasswordColumn);
	}

	//Get the user's email address
	public string GetUserEmail()
	{
		return this.GetString(((BaseClasses.IUserIdentityTable)this.TableAccess).UserEmailColumn);
	}

	//Get a list of roles to which the user belongs
	public string[] GetUserRoles()
	{
		string[] roles;
		if ((this as BaseClasses.IUserRoleRecord) != null)
		{
			string role = ((BaseClasses.IUserRoleRecord)this).GetUserRole();
			roles = new string[]{role};
		}
		else
		{
			BaseClasses.IUserRoleTable roleTable = 
				((BaseClasses.IUserIdentityTable)this.TableAccess).GetUserRoleTable();
			if (roleTable == null)
			{
				return null;
			}
			else
			{
				ColumnValueFilter filter = BaseFilter.CreateUserIdFilter(roleTable, this.GetUserId());
				BaseClasses.Data.OrderBy order = new BaseClasses.Data.OrderBy(false, false);
				BaseClasses.Data.BaseFilter join = null;
				ArrayList roleRecords = roleTable.GetRecordList(
					join, 
					filter, 
					null, 
					order, 
					BaseClasses.Data.BaseTable.MIN_PAGE_NUMBER, 
					BaseClasses.Data.BaseTable.MAX_BATCH_SIZE);
				ArrayList roleList = new ArrayList(roleRecords.Count);
				foreach (BaseClasses.IUserRoleRecord roleRecord in roleRecords)
				{
					roleList.Add(roleRecord.GetUserRole());
				}
				roles = (string[])roleList.ToArray(typeof(string));
			}
		}
		return roles;
	}

#endregion




#region "Convenience methods to get/set values of fields"

	/// <summary>
	/// This is a convenience method that provides direct access to the value of the record's Usuario_.id_usuario field.
	/// </summary>
	public ColumnValue Getid_usuarioValue()
	{
		return this.GetValue(TableUtils.id_usuarioColumn);
	}

	/// <summary>
	/// This is a convenience method that provides direct access to the value of the record's Usuario_.id_usuario field.
	/// </summary>
	public Int32 Getid_usuarioFieldValue()
	{
		return this.GetValue(TableUtils.id_usuarioColumn).ToInt32();
	}

	/// <summary>
	/// This is a convenience method that provides direct access to the value of the record's Usuario_.Nombre_usuario field.
	/// </summary>
	public ColumnValue GetNombre_usuarioValue()
	{
		return this.GetValue(TableUtils.Nombre_usuarioColumn);
	}

	/// <summary>
	/// This is a convenience method that provides direct access to the value of the record's Usuario_.Nombre_usuario field.
	/// </summary>
	public string GetNombre_usuarioFieldValue()
	{
		return this.GetValue(TableUtils.Nombre_usuarioColumn).ToString();
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.Nombre_usuario field.
	/// </summary>
	public void SetNombre_usuarioFieldValue(ColumnValue val)
	{
		this.SetValue(val, TableUtils.Nombre_usuarioColumn);
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.Nombre_usuario field.
	/// </summary>
	public void SetNombre_usuarioFieldValue(string val)
	{
		ColumnValue cv = new ColumnValue(val);
		this.SetValue(cv, TableUtils.Nombre_usuarioColumn);
	}
	/// <summary>
	/// This is a convenience method that provides direct access to the value of the record's Usuario_.password field.
	/// </summary>
	public ColumnValue GetpasswordValue()
	{
		return this.GetValue(TableUtils.passwordColumn);
	}

	/// <summary>
	/// This is a convenience method that provides direct access to the value of the record's Usuario_.password field.
	/// </summary>
	public string GetpasswordFieldValue()
	{
		return this.GetValue(TableUtils.passwordColumn).ToString();
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.password field.
	/// </summary>
	public void SetpasswordFieldValue(ColumnValue val)
	{
		this.SetValue(val, TableUtils.passwordColumn);
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.password field.
	/// </summary>
	public void SetpasswordFieldValue(string val)
	{
		ColumnValue cv = new ColumnValue(val);
		this.SetValue(cv, TableUtils.passwordColumn);
	}
	/// <summary>
	/// This is a convenience method that provides direct access to the value of the record's Usuario_.email field.
	/// </summary>
	public ColumnValue GetemailValue()
	{
		return this.GetValue(TableUtils.emailColumn);
	}

	/// <summary>
	/// This is a convenience method that provides direct access to the value of the record's Usuario_.email field.
	/// </summary>
	public string GetemailFieldValue()
	{
		return this.GetValue(TableUtils.emailColumn).ToString();
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.email field.
	/// </summary>
	public void SetemailFieldValue(ColumnValue val)
	{
		this.SetValue(val, TableUtils.emailColumn);
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.email field.
	/// </summary>
	public void SetemailFieldValue(string val)
	{
		ColumnValue cv = new ColumnValue(val);
		this.SetValue(cv, TableUtils.emailColumn);
	}


#endregion

#region "Convenience methods to get field names"

	/// <summary>
	/// This is a property that provides direct access to the value of the record's Usuario_.id_usuario field.
	/// </summary>
	public Int32 id_usuario
	{
		get
		{
			return this.GetValue(TableUtils.id_usuarioColumn).ToInt32();
		}
		set
		{
			ColumnValue cv = new ColumnValue(value);
			this.SetValue(cv, TableUtils.id_usuarioColumn);
		}
	}


	/// <summary>
	/// This is a convenience method that can be used to determine that the column is set.
	/// </summary>
	public bool id_usuarioSpecified
	{
		get
		{
			ColumnValue val = this.GetValue(TableUtils.id_usuarioColumn);
            if (val == null || val.IsNull)
            {
                return false;
            }
            return true;
		}
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.id_usuario field.
	/// </summary>
	public string id_usuarioDefault
	{
		get
		{
			return TableUtils.id_usuarioColumn.DefaultValue;
		}
	}
	/// <summary>
	/// This is a property that provides direct access to the value of the record's Usuario_.Nombre_usuario field.
	/// </summary>
	public string Nombre_usuario
	{
		get
		{
			return this.GetValue(TableUtils.Nombre_usuarioColumn).ToString();
		}
		set
		{
			ColumnValue cv = new ColumnValue(value);
			this.SetValue(cv, TableUtils.Nombre_usuarioColumn);
		}
	}


	/// <summary>
	/// This is a convenience method that can be used to determine that the column is set.
	/// </summary>
	public bool Nombre_usuarioSpecified
	{
		get
		{
			ColumnValue val = this.GetValue(TableUtils.Nombre_usuarioColumn);
            if (val == null || val.IsNull)
            {
                return false;
            }
            return true;
		}
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.Nombre_usuario field.
	/// </summary>
	public string Nombre_usuarioDefault
	{
		get
		{
			return TableUtils.Nombre_usuarioColumn.DefaultValue;
		}
	}
	/// <summary>
	/// This is a property that provides direct access to the value of the record's Usuario_.password field.
	/// </summary>
	public string password
	{
		get
		{
			return this.GetValue(TableUtils.passwordColumn).ToString();
		}
		set
		{
			ColumnValue cv = new ColumnValue(value);
			this.SetValue(cv, TableUtils.passwordColumn);
		}
	}


	/// <summary>
	/// This is a convenience method that can be used to determine that the column is set.
	/// </summary>
	public bool passwordSpecified
	{
		get
		{
			ColumnValue val = this.GetValue(TableUtils.passwordColumn);
            if (val == null || val.IsNull)
            {
                return false;
            }
            return true;
		}
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.password field.
	/// </summary>
	public string passwordDefault
	{
		get
		{
			return TableUtils.passwordColumn.DefaultValue;
		}
	}
	/// <summary>
	/// This is a property that provides direct access to the value of the record's Usuario_.email field.
	/// </summary>
	public string email
	{
		get
		{
			return this.GetValue(TableUtils.emailColumn).ToString();
		}
		set
		{
			ColumnValue cv = new ColumnValue(value);
			this.SetValue(cv, TableUtils.emailColumn);
		}
	}


	/// <summary>
	/// This is a convenience method that can be used to determine that the column is set.
	/// </summary>
	public bool emailSpecified
	{
		get
		{
			ColumnValue val = this.GetValue(TableUtils.emailColumn);
            if (val == null || val.IsNull)
            {
                return false;
            }
            return true;
		}
	}

	/// <summary>
	/// This is a convenience method that allows direct modification of the value of the record's Usuario_.email field.
	/// </summary>
	public string emailDefault
	{
		get
		{
			return TableUtils.emailColumn.DefaultValue;
		}
	}


#endregion
}

}
